home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * MacWriteImport.c *
- * *
- * Translator for reading a MacWrite file with XTND 1.3. *
- * *
- * Copyright © 1989,90 Claris Corporation *
- * All Rights Reserved *
- * *
- * Author: Richard Scorer *
- * Date: 13 April, 1988 *
- * *
- ************************************************************************/
-
- #include <Printing.h>
- #include <Resources.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <StandardFile.h>
- #include "CodeA5Globals.h"
- enum { FALSE, TRUE };
-
- #ifndef THINK_C
- #include "CodeA5Globals.h"
- #endif
-
- #include ":::XTND Headers:XTNDCIncludes:XTNDTextTranslator.h"
-
- #include "MacWrite.h" /* MacWrite 5.0 specific header */
-
-
- /*------------------------- Useful Constants ---------------------------*/
-
- /* version number of MacWrite that this translator recognizes */
- #define kValidVersionNum 6
-
- /*----------State defines----------*/
- #define kInitial 0
- #define kNewSrch 1
- #define kSameSrch 2
-
-
- /*-------------------------Global Variables-----------------------------*/
-
- static ImportParmBlkPtr gImportPBPtr;
- static MacWriteHeader *MWHeader; /* File header */
-
- /* paragraph info pointers */
- static unsigned char *gParagPtr, *gParagraph, *gParagPos;
- unsigned char *gCurrentFormat;
- static short gParagDLent;
- static Boolean gDidPicture; /* Indicator for PICT gParagraph */
- static unsigned char gCompressChars[15]; /* Compression string */
- static unsigned char gDefaultChars[16] = " etnroaisdlhcfp";
- static InfoStruct *gInfoArray; /* */
- static MacWriteWindow gTheWindow; /* Document window buffer */
- static short gParagCount; /* Total number of gParagraphs */
- static Fixed gSavePara[numParaFmts]; /* */
- static Fixed gSaveTab; /* */
- static Fixed gMarginWidth; /* */
- static Boolean gFoundString = FALSE; /* Compresson string resource found? */
-
-
- /*-------------------------Function prototypes--------------------------*/
-
- void main(ImportParmBlkPtr);
- static Boolean ValidApplHandle(Handle h);
- static void ImportMacWrite(ImportParmBlkPtr);
- static void GetResources(void);
- static long InitAll(void);
- static long InitStory(void);
- static void DecompressData(void);
- static Boolean GetPict(InfoStruct *);
- static Boolean CheckPageBreak(InfoStruct *);
- static void CreateParagraph(InfoStruct *, short *, short *, short *, short *, short *, short);
- static void GetRulerInfo(InfoStruct *, short *);
- static short GetMacWriteData(void);
- static void CleanUp(void);
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* main This is the main routine and the only entry point for the */
- /* the translator. */
- /* NOTE: This translator uses globals that are used from the first to */
- /* last call. The first call should be with the IMPORT_GET_RESOURCES */
- /* directive, at which time the globals will be allocated. However, if */
- /* for some reason the application does not make the first call with */
- /* the IMPORT_GET_RESOURCES directive then the translator must */
- /* allocate the globals when it receives the IMPORT_INIT_ALL */
- /* directive. The rub is that there is no way to know for sure if the */
- /* globals have already been allocated. So we do the best that we can */
- /* by simply testing to see if the GlobalHandle field of the import */
- /* parameter block contains what appears to be a valid handle. Note to */
- /* this note: this note does NOT apply if you are using Think C’s */
- /* A4-based globals. */
- /* */
- /*----------------------------------------------------------------------*/
- void main(importParamPtr)
- ImportParmBlkPtr importParamPtr;
- {
- #ifdef THINK_C
- asm {
- move.l a4,-(sp)
- move.l a0,a4 ; Sets up the globals for this CODE
- }
- #else
- long savedA5;
-
- if (importParamPtr->directive == importGetResources ||
- (importParamPtr->directive == importInitAll &&
- !ValidApplHandle(importParamPtr->globalHandle))) {
- importParamPtr->globalHandle = NewHandle(0L);
- MakeA5World(importParamPtr->globalHandle);
- }
- savedA5 = SetA5World(importParamPtr->globalHandle);
- #endif
-
- ImportMacWrite(importParamPtr);
-
- #ifdef THINK_C
- asm {
- move.l (sp)+,a4
- }
- #else
- RestoreA5World(savedA5, importParamPtr->globalHandle);
- if (importParamPtr->directive == importCloseAll) {
- DisposeA5World(importParamPtr->globalHandle);
- importParamPtr->globalHandle = NULL;
- }
- #endif
- }
-
-
- #ifndef THINK_C
- /*----------------------------------------------------------------------*/
- /* */
- /* ValidApplHandle attempts to determine if the handle h is a valid */
- /* handle in the current application zone. It checks to see that h is */
- /* word aligned, and is within the application zone. It also checks */
- /* to see if *h is word aligned, and is within the application zone. */
- /* Finally, it checks to see if RecoverHandle(*h) == h. It returns */
- /* FALSE as the function return value if any test fails, otherwise it */
- /* returns TRUE. */
- /* */
- /*----------------------------------------------------------------------*/
- Boolean ValidApplHandle(Handle h)
- {
- Ptr p, hiZ, loZ;
-
- if ((unsigned long)h & 1)
- return(FALSE);
- if ((Ptr)h < (loZ = StripAddress(ApplicZone())) || (Ptr)h > (hiZ = StripAddress(GetApplLimit())))
- return(FALSE);
- if ((unsigned long)(p = StripAddress(*h)) & 1)
- return(FALSE);
- if (p < loZ || p > hiZ)
- return(FALSE);
- return(RecoverHandle(p) == h);
- }
- #endif
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* ImportMacWrite dispatches the call to the appropriate routine */
- /* depending on the Directive. */
- /* */
- /*----------------------------------------------------------------------*/
- void ImportMacWrite(ImportParmBlkPtr importParamPtr)
- {
- gImportPBPtr = importParamPtr;
-
- switch (importParamPtr->directive) {
- case importGetResources:
- GetResources();
- break;
-
- case importInitAll:
- gImportPBPtr->textLength = InitAll();
- break;
-
- case importInitHeader:
- case importInitFooter:
- case importInitMain:
- gImportPBPtr->textLength = InitStory();
- break;
-
- case importGetText:
- gImportPBPtr->textLength = GetMacWriteData();
- break;
-
- case importCloseAll:
- CleanUp();
- break;
-
- default:
- break;
- }
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* GetResources gets all necessary resources from file. For MacWrite, */
- /* this means the compression characters. */
- /* */
- /*----------------------------------------------------------------------*/
- static void GetResources()
- {
- register Handle thechars;
-
- /* read in the compression characters */
- if (thechars = (Handle)GetResource('STR ', 700)) {
- gFoundString = TRUE;
- BlockMove((*thechars) + 1, gCompressChars, 15);
- }
- ReleaseResource(thechars);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* CleanUp handles clean up after import is finished. */
- /* Currently it just disposes of storage. */
- /* */
- /*----------------------------------------------------------------------*/
- static void CleanUp()
- {
- DisposPtr((Ptr)MWHeader);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* InitAll initializes reading of MacWrite documents. */
- /* */
- /*----------------------------------------------------------------------*/
- static long InitAll()
- {
- long count;
- register long rqrdsize;
- Rect paperRect, pageRect;
-
- /* get compression characters */
- if (!gFoundString)
- BlockMove(gDefaultChars, gCompressChars, 15);
- gFoundString = FALSE;
-
- /* init header */
- MWHeader = (MacWriteHeader *) NewPtr(sizeof(MacWriteHeader));
- if (gImportPBPtr->result = MemError()) return (0);
-
- /* read in the MacWrite header information */
- gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, 0L);
- count = sizeof(MacWriteHeader);
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, MWHeader))return (0);
-
- /* Check version number */
- if (MWHeader->versionNo != kValidVersionNum)
- {
- gImportPBPtr->result = badImportFileErr;
- return (0);
- }
-
- /* set up the print record */
- gImportPBPtr->printRecord = (THPrint)NewHandle(sizeof(TPrint));
- if (gImportPBPtr->result = MemError()) return (0);
- BlockMove(&MWHeader->printRecord, *gImportPBPtr->printRecord, sizeof(TPrint));
-
- /* Sure wish I could validate the print record here...*/
-
- paperRect = (*(THPrint)gImportPBPtr->printRecord)->rPaper;
- pageRect = (*(THPrint)gImportPBPtr->printRecord)->prInfo.rPage;
-
- gImportPBPtr->hRes = (*(THPrint)gImportPBPtr->printRecord)->prInfo.iHRes;
- gImportPBPtr->vRes = (*(THPrint)gImportPBPtr->printRecord)->prInfo.iVRes;
- gImportPBPtr->topMargin = (Fixed)(0 - paperRect.top) << 16;
- gImportPBPtr->leftMargin = (Fixed)(gImportPBPtr->hRes) << 16; /* 1 inch */
- gImportPBPtr->bottomMargin = (Fixed)(paperRect.bottom - pageRect.bottom) << 16;
- gImportPBPtr->rightMargin = (Fixed)(paperRect.right - pageRect.right) << 16;
-
- gMarginWidth = ((long)paperRect.right - paperRect.left) << 16;
-
- /* set up the default information for the document */
- gImportPBPtr->autoHyphenate = FALSE;
- gImportPBPtr->startPageNum = MWHeader->startPageNum;
- gImportPBPtr->rulerShowing = !MWHeader->rulersHidden;
- gImportPBPtr->doubleSided = FALSE;
- gImportPBPtr->titlePage = MWHeader->titlePage;
- gImportPBPtr->showInvisibles = FALSE;
- gImportPBPtr->showPageGuides = FALSE;
- gImportPBPtr->showPictures = TRUE;
-
- /* subtract width of margins */
- gMarginWidth -= (gImportPBPtr->leftMargin + gImportPBPtr->rightMargin);
-
- gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, 0L);
- rqrdsize = 0;
- gImportPBPtr->translatorState = kInitial;
- gDidPicture = FALSE;
- return (rqrdsize);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* InitStory initializes the reading of headers, footers, main. */
- /* */
- /*----------------------------------------------------------------------*/
- static long InitStory()
- {
- long count = 0;
-
- /* see if we have the requested item (header, footer, etc.) */
- switch (gImportPBPtr->currentStory)
- {
- case headerStory:
- if (MWHeader->headerDisplay)
- {
- gImportPBPtr->directive = importAcknowledge;
- count = 206L;
- gParagCount = MWHeader->headerPars;
- }
- break;
-
- case footerStory:
- if (MWHeader->footerDisplay)
- {
- gImportPBPtr->directive = importAcknowledge;
- count = 160L;
- gParagCount = MWHeader->footerPars;
- }
- break;
-
- case mainStory:
- gImportPBPtr->directive = importAcknowledge;
- count = 252L;
- gParagCount = MWHeader->mainPars;
- break;
- }
-
- if (count) {
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, count))
- return(0);
-
- /* read in the window information */
- count = sizeof(MacWriteWindow);
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, &gTheWindow))
- return(0);
-
- /* read in the information array */
- gInfoArray = (InfoStruct *)NewPtr((long)gTheWindow.infoAryLength);
- if (gImportPBPtr->result = MemError())
- return(0);
-
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, gTheWindow.infoAryPos))
- return(0);
- count = gTheWindow.infoAryLength;
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, gInfoArray))
- return(0);
-
- /* Autogrow the headers and footers */
- gImportPBPtr->storyHeight = 0;
- if (gImportPBPtr->currentStory != mainStory) {
- /* set up page, date, and time information */
- gImportPBPtr->pagePoint = *(Point *)&gTheWindow.pageNumPos;
- gImportPBPtr->datePoint = *(Point *)&gTheWindow.datePos;
- gImportPBPtr->timePoint = *(Point *)&gTheWindow.timePos;
- }
- }
-
- gImportPBPtr->translatorState = kInitial;
- gDidPicture = FALSE;
- return(0);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* DecompressData decompresses the data as it is read in from the */
- /* MacWrite file. */
- /* */
- /*----------------------------------------------------------------------*/
- static void DecompressData()
- {
- register unsigned char *dcompar, *dcomparpos, *chk1buf, *chk2buf;
- unsigned char leftnibl, rightnibl;
- unsigned char *tmpfrmtpos, *tmpptr;
- register short frmtlent, i;
-
- dcompar = (unsigned char *)NewPtr((long) gParagDLent);
- if (gImportPBPtr->result = MemError()) return;
- dcomparpos = dcompar;
- for (; (dcomparpos - dcompar) < (long) gParagDLent; gParagPos++) {
- leftnibl = (*gParagPos & 0xF0) >> 4;
- rightnibl = *gParagPos & 0x0F;
- if (leftnibl == 0x0F) {
- *dcomparpos++ = (rightnibl << 4) | ((*(++gParagPos) & 0xF0) >> 4);
- if ((dcomparpos - dcompar) == (long) gParagDLent) continue;
- rightnibl = *gParagPos & 0x0F;
- }
- else *dcomparpos++ = gCompressChars[leftnibl];
- if (rightnibl == 0x0F) *dcomparpos++ = *(++gParagPos);
- else *dcomparpos++ = gCompressChars[rightnibl];
- }
- gCurrentFormat = gParagPos + ((gParagPos - gParagraph) & 1);
- frmtlent = *(short *)gCurrentFormat;
- tmpptr = (unsigned char *)NewPtr((long)gParagDLent + frmtlent + 2L);
- if (gImportPBPtr->result = MemError()) return;
- chk1buf = tmpptr;
- chk2buf = dcompar;
- for (i = 0; i < gParagDLent; i++) *chk1buf++ = *chk2buf++;
- if (gParagDLent & 1) *chk1buf++ = 0x00;
- tmpfrmtpos = chk1buf;
- chk2buf = gCurrentFormat;
- for (i = 0; i < frmtlent + 2; i++) *chk1buf++ = *chk2buf++;
- if (gParagPtr)
- {
- DisposPtr((Ptr)gParagPtr);
- gParagPtr = 0;
- }
- DisposPtr((Ptr)dcompar);
- gParagPtr = gParagraph = tmpptr;
- gParagPos = gParagraph;
- gCurrentFormat = tmpfrmtpos;
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* GetPict attempts to read in a MacWrite picture. */
- /* */
- /*----------------------------------------------------------------------*/
- static Boolean GetPict(infoitem)
- register InfoStruct *infoitem;
- {
- long count;
- register PictMisc **pmisc;
- PictureParagraph theParagraph;
- register PicHandle thePicture;
-
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, infoitem->Status.paraFilePosn)) return (FALSE);
- count = (long) sizeof(PictureParagraph);
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, &theParagraph)) return (FALSE);
- count = (long) theParagraph.thePicture.picSize;
-
- /* read in the picture */
- thePicture = (PicHandle) NewHandle((Size)count);
- if (gImportPBPtr->result = MemError()) return (FALSE);
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, infoitem->Status.paraFilePosn + 8)) return (FALSE);
- HLock((Handle)thePicture);
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, *thePicture)) return (FALSE);
- HUnlock((Handle)thePicture);
-
- /* set up the miscdata */
- pmisc = (PictMisc **)NewHandle(sizeof(PictMisc));
- if (gImportPBPtr->result = MemError())
- {
- DisposHandle((Handle)thePicture);
- return (FALSE);
- }
- (*pmisc)->thePicture = thePicture;
- (*pmisc)->pictSize = count;
- (*pmisc)->destRect = theParagraph.pictureSize;
- (*pmisc)->origRect = (*thePicture)->picFrame;
- gImportPBPtr->miscData = (long) pmisc;
- /* set up left indent so that picture is in the right place */
- gImportPBPtr->paraFmts[0] = (long)theParagraph.pictureSize.left << 16;
- gImportPBPtr->paraFmts[1] = 0L;
- gImportPBPtr->tabs[0].tabIndent = -1L;
- return (TRUE);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* CheckPageBreak checks the page breaks, and returns them as 0x0C. */
- /* */
- /*----------------------------------------------------------------------*/
- static Boolean CheckPageBreak(InfoStruct *infoitem)
- {
- long count;
- Rect picturerect;
- PictureParagraph theParagraph;
-
- if (infoitem->paraLen <= 18) return
- (FALSE);
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, infoitem->Status.paraFilePosn))
- return(FALSE);
- count = (long)sizeof(PictureParagraph);
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, &theParagraph))
- return(FALSE);
- picturerect = theParagraph.thePicture.picFrame;
- if ( picturerect.top == 'MA' &&
- picturerect.left == 'GI' &&
- picturerect.bottom == 'CP' &&
- picturerect.right == 'IC')
- return (TRUE);
- else
- return (FALSE);
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* CreateParagraph creates a gParagraph. */
- /* */
- /*----------------------------------------------------------------------*/
- static void CreateParagraph(infoitem, frmtlent, frmtcnt, curface, cursize, curfont, justfctn)
- register InfoStruct *infoitem;
- register short *frmtlent, *frmtcnt;
- short *curface, *cursize, *curfont, justfctn;
- {
- #define COMPBITMASK 0x08 /* if this bit is set, the text is compressed */
- #define JUSTBITMASK 0x40 /* if this bit is set, use the parag just, not ruler */
- #define JUSTCODEMASK 0x03 /* the justification code for this gParagraph */
-
- long count;
-
- if ((infoitem->Status.justCode) & JUSTBITMASK)
- gImportPBPtr->txtJust = (short) ((infoitem->Status.justCode) & JUSTCODEMASK);
- else
- gImportPBPtr->txtJust = justfctn;
-
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, infoitem->Status.paraFilePosn)) return;
- count = (long) infoitem->paraLen;
- gParagPtr = gParagraph = (unsigned char *)NewPtr((long) count);
-
- if (gImportPBPtr->result = MemError()) return;
- if (gImportPBPtr->result = FSRead(gImportPBPtr->refNum, &count, gParagraph)) return;
-
- gParagDLent = *(short *)gParagraph;
- gParagraph += 2;
- gParagPos = gParagraph;
- gCurrentFormat = gParagPos + gParagDLent + (gParagDLent & 1);
-
- /* if necessary, decompress data */
- if ((infoitem->Status.justCode) & COMPBITMASK) DecompressData();
-
- *frmtlent = *(short *)gCurrentFormat;
- gCurrentFormat += 4;
- *frmtcnt = 0;
- *cursize = (short) *gCurrentFormat++;
- *curface = (short) *gCurrentFormat++;
- *curfont = *(short *)gCurrentFormat;
- gCurrentFormat += 2;
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* GetRulerInfo gets the gParagraph information from ruler. */
- /* */
- /*----------------------------------------------------------------------*/
- static void GetRulerInfo(infoitem, justfctn)
- register InfoStruct *infoitem;
- short *justfctn;
- {
- long count;
- RulerParagraph theParagraph;
- register short i;
- register Fixed tabValue;
-
- gImportPBPtr->txtJust = textLeft;
-
- for (i = 0; i < numParaFmts; i++) gImportPBPtr->paraFmts[i] = 0;
- for (i = 0; i < maxTabs; i++) gImportPBPtr->tabs[i].tabIndent = -1;
-
- if (gImportPBPtr->result = SetFPos(gImportPBPtr->refNum, fsFromStart, infoitem->Status.paraFilePosn)) return;
-
- count = (long) sizeof(RulerParagraph);
- if (FSRead(gImportPBPtr->refNum, &count, &theParagraph)) return;
-
- gImportPBPtr->paraFmts[0] = (Fixed)theParagraph.leftMargin << 16;
- gImportPBPtr->paraFmts[1] = ((Fixed)theParagraph.lineIndent << 16) - gImportPBPtr->paraFmts[0];
- gImportPBPtr->paraFmts[2] = gMarginWidth - ((Fixed)theParagraph.rightMargin << 16);
-
- /* adjust for 1/16 measurements */
- for (i = 0;i<3;i++) {
- if ((((gImportPBPtr->paraFmts[i] >> 16) % 72) - 4) % 9 == 0)
- gImportPBPtr->paraFmts[i] += 0x8000;
- }
-
- if (gImportPBPtr->paraFmts[0] < 0) gImportPBPtr->paraFmts[0] = 0;
- if (gImportPBPtr->paraFmts[0] + gImportPBPtr->paraFmts[1] < 0) gImportPBPtr->paraFmts[1] = gImportPBPtr->paraFmts[0];
- if (gImportPBPtr->paraFmts[2] < 0) gImportPBPtr->paraFmts[2] = 0;
-
- gImportPBPtr->txtJust = *justfctn = (short) theParagraph.justification;
- if (theParagraph.lineSpacing & 0x8000) {
- gImportPBPtr->paraFmts[6] = 0L;
- /* the six lines per inch madness is active */
- switch (theParagraph.lineSpacing & 0x00FF) {
- case 0: gImportPBPtr->paraFmts[3] = (long)12 << 16; break;
- case 1: gImportPBPtr->paraFmts[3] = (long)18 << 16; break;
- case 2: gImportPBPtr->paraFmts[3] = (long)24 << 16; break;
- default: gImportPBPtr->paraFmts[3] = (long)12 << 16; break;
- }
- } else {
- gImportPBPtr->paraFmts[6] = -1L;
- switch (theParagraph.lineSpacing & 0x00FF) {
- case 0: gImportPBPtr->paraFmts[3] = 0L; break; /* single line spacing */
- case 1: gImportPBPtr->paraFmts[3] = 0x08000; break; /* 1 1/2 line spacing */
- case 2: gImportPBPtr->paraFmts[3] = 0x10000; break; /* double line spacing */
- default: gImportPBPtr->paraFmts[3] = 0L; break; /* single line spacing */
- }
- }
-
- for (i = 0; i < theParagraph.numTabs; i++) {
- tabValue = theParagraph.tabArray[i];
- if (tabValue < 0) {
- gImportPBPtr->tabs[i].tabJust = textDecimal;
- tabValue = -tabValue;
- } else
- gImportPBPtr->tabs[i].tabJust = textLeft;
-
- gImportPBPtr->tabs[i].tabLead = ' ';
- gImportPBPtr->tabs[i].tabIndent = (Fixed)tabValue << 16;
-
- /* adjust for 1/16 measurements */
- if (((tabValue % 72) - 4) % 9 == 0)
- gImportPBPtr->tabs[i].tabIndent += 0x8000;
- }
-
- /* save this information in case we have to change it for a gParagraph */
- for (i = 0; i < numParaFmts; i++) gSavePara[i] = gImportPBPtr->paraFmts[i];
- gSaveTab = gImportPBPtr->tabs[0].tabIndent;
- }
-
-
- /*----------------------------------------------------------------------*/
- /* */
- /* GetMacWriteData reads the text in from the MacWrite file. */
- /* */
- /*----------------------------------------------------------------------*/
- static short GetMacWriteData()
- {
- register short *face = &gImportPBPtr->txtFace,
- *size = &gImportPBPtr->txtSize,
- *font = &gImportPBPtr->txtFont,
- paraghit;
- short i;
- InfoStruct *infoitem;
-
- static short infoindex;
- static short cursize, curface, curfont;
- static short frmtlent, frmtcnt, justfctn;
- static long srchlmt;
- static Ptr tmpstrpos;
-
- gImportPBPtr->txtColor = textBlack;
-
- switch (gImportPBPtr->translatorState)
- {
- case kInitial:
- gParagPtr = (unsigned char *) 0;
-
- /* Set up initial ruler information */
- for (infoindex = 0, paraghit = 0; ((paraghit == 0) && (infoindex < gParagCount)); infoindex++)
- {
- infoitem = &gInfoArray[infoindex];
- paraghit = infoitem->paraHeight;
- if (paraghit == 0) {
- GetRulerInfo(infoitem, &justfctn);
- if (gImportPBPtr->result) return (0);
- }
- }
- if (paraghit == 0) {
- /* There is no text in this MacWrite document. return 0. */
- DisposPtr((Ptr)gInfoArray);
- gImportPBPtr->directive = importAcknowledge;
- return (0);
- }
- if (paraghit < 0) {
- /* This is a picture gParagraph. */
- gParagDLent = srchlmt = 0L;
- gImportPBPtr->translatorState = kNewSrch;
- *size = 12;
- *face = textPlain;
- *font = geneva;
-
- /* Check to see if this a page break gParagraph. */
- if (CheckPageBreak(infoitem)) {
- *gImportPBPtr->textBuffer = 0x0C;
- return (1);
- } else {
- /* Attempt to read in the picture. */
- if (GetPict(infoitem)) {
- *gImportPBPtr->textBuffer = floatingPict;
- gDidPicture = TRUE;
- /* make sure gParagraph is single spaced */
- gImportPBPtr->paraFmts[6] = -1L;
- gImportPBPtr->paraFmts[3] = 0L;
- return (1);
- } else {
- gImportPBPtr->directive = importAcknowledge;
- return (0);
- }
- }
- }
- /* We now know this is a text gParagraph. */
- CreateParagraph(infoitem, &frmtlent, &frmtcnt, &curface,
- &cursize, &curfont, justfctn);
- if (gImportPBPtr->result) return (0);
-
- if (frmtlent == (frmtcnt + 1) * 6)
- srchlmt = (long)gParagDLent;
- else {
- srchlmt = (long) *(short *)gCurrentFormat;
- gCurrentFormat += 2;
- }
- tmpstrpos = gImportPBPtr->textBuffer;
- for (; ((tmpstrpos - gImportPBPtr->textBuffer) < (long)256 ) &&
- ((gParagPos - gParagraph) < srchlmt);)
- *tmpstrpos++ = *gParagPos++;
-
- if ((gParagPos - gParagraph) == srchlmt)
- gImportPBPtr->translatorState = kNewSrch;
- else
- gImportPBPtr->translatorState = kSameSrch;
- *size = cursize;
- *face = curface;
- *font = curfont;
- return ((short)(tmpstrpos - gImportPBPtr->textBuffer));
- break;
-
- case kNewSrch:
- if (gDidPicture) {
- /* A picture was inserted. Put a return character in. */
- *size = 12;
- *face = textPlain;
- *font = geneva;
- gParagDLent = 0;
- srchlmt = (long)gParagDLent;
- gImportPBPtr->translatorState = kNewSrch;
- *gImportPBPtr->textBuffer = returnChar;
- gDidPicture = FALSE;
- return (1);
- } else {
- for (i = 0; i < numParaFmts; i++)
- gImportPBPtr->paraFmts[i] = gSavePara[i];
- gImportPBPtr->tabs[0].tabIndent = gSaveTab;
- }
- if (srchlmt == (long)gParagDLent) {
- if (gParagPtr) {
- DisposPtr((Ptr)gParagPtr);
- gParagPtr = 0;
- }
- for (paraghit = 0;((paraghit == 0) && (infoindex < gParagCount)); infoindex++)
- {
- infoitem = &gInfoArray[infoindex];
- paraghit = infoitem->paraHeight;
- if (paraghit == 0) {
- GetRulerInfo(infoitem, &justfctn);
- if (gImportPBPtr->result) return (0);
- }
- }
- if (paraghit == 0) {
- DisposPtr((Ptr)gInfoArray);
- gImportPBPtr->directive = importAcknowledge;
- return (0);
- }
- if (paraghit < 0) {
- /* This is a picture gParagraph. */
- gParagDLent = 0;
- srchlmt = (long)gParagDLent;
- gImportPBPtr->translatorState = kNewSrch;
- *size = 12;
- *face = textPlain;
- *font = geneva;
-
- /* Check to see if this a page break gParagraph. */
- if (CheckPageBreak(infoitem)) {
- *gImportPBPtr->textBuffer = 0x0C;
- return (1);
- } else {
- if (GetPict(infoitem)) {
- /* Attempt to read in the picture. */
- *gImportPBPtr->textBuffer = floatingPict;
- gDidPicture = TRUE;
- /* make sure gParagraph is single spaced */
- gImportPBPtr->paraFmts[6] = -1L;
- gImportPBPtr->paraFmts[3] = 0L;
- return (1);
- } else {
- gImportPBPtr->directive = importAcknowledge;
- return (0);
- }
- }
- }
- /* We now know this is a text gParagraph. */
- CreateParagraph(infoitem, &frmtlent, &frmtcnt, &curface,
- &cursize, &curfont, justfctn);
- if (gImportPBPtr->result) return (0);
- if (frmtlent == (frmtcnt + 1) * 6)
- srchlmt = (long)gParagDLent;
- else {
- srchlmt = (long) *(short *)gCurrentFormat;
- gCurrentFormat += 2;
- }
- tmpstrpos = gImportPBPtr->textBuffer;
- while (tmpstrpos - gImportPBPtr->textBuffer < (long)256 &&
- gParagPos - gParagraph < srchlmt)
- *tmpstrpos++ = *gParagPos++;
-
- if ((gParagPos - gParagraph) != srchlmt)
- gImportPBPtr->translatorState = kSameSrch;
- *size = cursize;
- *face = curface;
- *font = curfont;
- return ((short)(tmpstrpos - gImportPBPtr->textBuffer));
- } else {
- frmtcnt++;
- cursize = (short) *gCurrentFormat++;
- curface = (short) *gCurrentFormat++;
- curfont = *(short *)gCurrentFormat;
- gCurrentFormat += 2;
-
- if (frmtlent == (frmtcnt + 1) * 6)
- srchlmt = (long)gParagDLent;
- else {
- srchlmt = (long) *(short *)gCurrentFormat;
- gCurrentFormat += 2;
- }
- tmpstrpos = gImportPBPtr->textBuffer;
- for (; ((tmpstrpos - gImportPBPtr->textBuffer) < (long)256) &&
- ((gParagPos - gParagraph) < srchlmt);)
- *tmpstrpos++ = *gParagPos++;
-
- if ((gParagPos - gParagraph) != srchlmt)
- gImportPBPtr->translatorState = kSameSrch;
- *size = cursize;
- *face = curface;
- *font = curfont;
- return ((short)(tmpstrpos - gImportPBPtr->textBuffer));
- }
- break;
-
- case kSameSrch:
- tmpstrpos = gImportPBPtr->textBuffer;
- for (; ((tmpstrpos - gImportPBPtr->textBuffer) < (long)256) &&
- ((gParagPos - gParagraph) < srchlmt);)
- *tmpstrpos++ = *gParagPos++;
-
- if ((gParagPos - gParagraph) == srchlmt)
- gImportPBPtr->translatorState = kNewSrch;
- *size = cursize;
- *face = curface;
- *font = curfont;
- return ((short)(tmpstrpos - gImportPBPtr->textBuffer));
- break;
- }
- }
-